<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的草稿</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <link rel="stylesheet" href="css/list.css">
    <script src="js/jquery.min.js"></script>
    <script src="./js/logout.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/logo.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer" style="width: 50%;"></span>
        <a href="blog_list.html">博客广场</a>
        <a href="myblog_list.html">个人博客</a>
        <a href="personal_center.html">个人中心</a>
        <a href="my_relation_following.html">我的关注/粉丝</a>
        <a href="private_message.html">聊天室</a>
        <a href="blog_add.html">写博客</a>
        <a href="javascript:logout()">注销</a>
    </div>

    <!-- 版心 -->
    <div class="container">
        <!-- 左侧个人信息 -->
        <div class="container-left" style="display: none;">
            <div class="card">
                <img src="img/avatar.png" class="avtar" alt="">
                <h3></h3>
                <a href="http:www.github.com">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>2</span>
                    <span>1</span>
                </div>
            </div>
        </div>
        <!-- 右侧内容详情 -->
        <div id="artlist" class="container-right" style="margin-left: 10%;">
            <!-- 每一篇博客包含标题, 摘要, 时间 -->
            <!-- <div class="blog">
                <div class="title">我的第一篇博客</div>
                <div class="date">2021-06-02</div>
                <div class="desc">
                    从今天起, 我要认真敲代码. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Cum distinctio ullam eum ut
                    veroab laborum numquam tenetur est in dolorum a sint, assumenda adipisci similique quaerat vel.
                </div>
                <a href="blog_edit.html?id=1" class="detail">继续编写 &gt;&gt;</a>&nbsp;&nbsp;
                <a href="javascript:del(1)" class="detail">删除 &gt;&gt;</a>
            </div> -->
        </div>
    </div>

    <script>
        function getMyDraftList() {
            jQuery.ajax({
                url: "art/mydraftlist",
                type: "POST",
                data: {},
                success: function (res) {
                    if (res.code == 200 && res.data.length > 0) {
                        // for 拼接 div，最终放到 mylist
                        var arthtml = "";
                        for (var i = 0; i < res.data.length; i++) {
                            var art = res.data[i];
                            arthtml += '<div class="blog">';
                            arthtml += '<div class="title">' + art.title + '</div>';
                            arthtml += '<div class="date">' + art.createtime + '</div>';
                            arthtml += '<div class="desc">';
                            arthtml += art.content;
                            arthtml += '</div>';
                            arthtml += '<a href="blog_edit.html?id=' + art.id + '" class="detail">继续编写 &gt;&gt;</a>&nbsp;&nbsp;';
                            arthtml += '<a href="javascript:del(' + art.id + ')" class="detail">删除 &gt;&gt;</a>';
                            arthtml += '</div>';

                        }
                        jQuery("#artlist").html(arthtml);
                    } else {
                        // 暂无文章
                        jQuery("#artlist").html("<h2 style = 'margin-left:100px;margin-top:100px'>暂无草稿！</h2>")
                    }
                }
            });
        }

        getMyDraftList();

        function del(id) {
            if (confirm("确认删除该草稿？")) {
                jQuery.ajax({
                    url: "art/del",
                    type: "POST",
                    data: { "id": id },
                    success: function (res) {
                        if (res.code == 200 && res.data == 1) {
                            alert("删除成功！");
                            location.href = "draft_list.html";
                        } else {
                            alert("操作失败，请重试！" + res.msg);
                        }
                    }
                });
            }
        }

    </script>
</body>

</html>